home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / MSJV7_2B.ARJ / SRVRDEMO.H < prev    next >
C/C++ Source or Header  |  1992-03-01  |  11KB  |  327 lines

  1. /*
  2.   OLE SERVER DEMO   
  3.   SrvrDemo.h
  4.  
  5.   This file contains typedefs, defines, global variable declarations, and
  6.   function prototypes.
  7.  
  8.   (c) Copyright Microsoft Corp. 1990 - 1992 All Rights Reserved    
  9. */
  10.  
  11.  
  12. /*
  13.    Explanation of Function Comments.
  14.  
  15.    Every function has a comment preceding it which gives the following
  16.    information:
  17.  
  18.    1) Function name.
  19.    2) A description of what the function does.
  20.    3) A list of parameters, each with its type and a short description.
  21.    4) A list of return values, each with an explanation of the condition that
  22.       will cause the function to return that value.
  23.    5) A customization section giving tips on how to customize this function
  24.       for your OLE application.
  25.       If the customization section says "None" then you may find the function
  26.       usable as is.    
  27.       If the customization section says "Re-implement" then the function
  28.       should still serve the same purpose and do what is indicated in the
  29.       function comment, but will probably need to be re-implemented for
  30.       your particular application.  Any Server Demo code relating to OLE
  31.       will be useful as a guide in your re-implementation.
  32.       If the customization section says "Server Demo specific" then the
  33.       function will probably have no counterpart in your application.
  34. */
  35.  
  36.  
  37. /* Menu Identifiers */
  38.  
  39. // File menu 
  40.  
  41. #define IDM_NEW      100
  42. #define IDM_OPEN     101   
  43. #define IDM_SAVE     102   
  44. #define IDM_SAVEAS   103
  45. #define IDM_EXIT     104
  46. #define IDM_ABOUT    105
  47. #define IDM_UPDATE   106
  48.  
  49. // Edit menu 
  50.  
  51. #define IDM_CUT      107  
  52. #define IDM_COPY     108   
  53. #define IDM_DELETE   109
  54.  
  55. // Color menu 
  56.  
  57. #define IDM_RED      110
  58. #define IDM_GREEN    111
  59. #define IDM_BLUE     112
  60. #define IDM_WHITE    113
  61. #define IDM_GRAY     114
  62. #define IDM_CYAN     115
  63. #define IDM_MAGENTA  116
  64. #define IDM_YELLOW   117
  65.  
  66. // New object menu 
  67.  
  68. #define IDM_NEWOBJ   118
  69. #define IDM_NEXTOBJ  119
  70.  
  71. #define IDD_CONTINUEEDIT    120
  72. #define IDD_UPDATEEXIT      121
  73. #define IDD_TEXT            122
  74.  
  75. #define OBJECT_WIDTH        120
  76. #define OBJECT_HEIGHT       60
  77.  
  78. // number HIMETRIC units per inch
  79. #define  HIMETRIC_PER_INCH  2540
  80.  
  81. /* Types */
  82.  
  83. // Document type
  84.  
  85. typedef enum
  86. {
  87.     doctypeNew,      // The document is untitled.
  88.     doctypeFromFile, // The document exists in a file and may be linked.
  89.     doctypeEmbedded, // The document is an embedded document.
  90. } DOCTYPE;
  91.  
  92.  
  93. // Device context type, passed to DrawObj.
  94.  
  95. typedef enum
  96. {
  97.    dctypeScreen,        
  98.    dctypeBitmap,        
  99.    dctypeMetafile
  100. } DCTYPE ;
  101.  
  102.  
  103. // Version 
  104.  
  105. typedef int VERSION;
  106.  
  107.  
  108. // Verb
  109.  
  110. typedef enum
  111. {
  112.    verbPlay = OLEVERB_PRIMARY,
  113.    verbEdit
  114. } VERB;
  115.  
  116.  
  117. // Server structure 
  118.  
  119. typedef struct
  120. {
  121.     OLESERVER     olesrvr;        // This must be the first field so that 
  122.                                   //   an LPOLESERVER can be cast to a SRVR*.
  123.     LHSERVER      lhsrvr;         // Registration handle
  124. } SRVR ;
  125.  
  126.  
  127. // How many objects (distinct numbers) will we allow?
  128. #define cfObjNums 20
  129.  
  130. // How many distinct clients can be associated with the object?
  131. #define clpoleclient 20
  132.  
  133.  
  134. // Document structure 
  135.  
  136. typedef struct  
  137. {
  138.     OLESERVERDOC oledoc;      // This must be the first field so that an
  139.                               //   LPOLESERVERDOC can be cast to an DOC*.
  140.     LHSERVERDOC  lhdoc;       // Registration handle
  141.     DOCTYPE      doctype;     // Document type
  142.     ATOM         aName;       // Document name
  143.     HPALETTE     hpal;        // Handle to a logical color palette
  144.     BYTE         rgfObjNums[cfObjNums+1]; // What object numbers have been used
  145. } DOC, *DOCPTR ;
  146.  
  147.  
  148. // Native data structure 
  149.  
  150. typedef struct  
  151. {
  152.     int         idmColor;        
  153.     int         nWidth; 
  154.     int         nHeight;
  155.     int         nX;
  156.     int         nY;
  157.     int         nHiMetricWidth;  // Used by an object handler.  These two fields
  158.     int         nHiMetricHeight; // always correspond to nWidth and nHeight.
  159.     VERSION     version;
  160.     char        szName[10];      // "Object nn"
  161. } NATIVE, FAR *LPNATIVE;
  162.  
  163.  
  164. // Object structure 
  165.  
  166. /* Ordinarily, an OBJ structure would not contain native data.  Rather, it
  167.    would contain a pointer (or some other reference) to the native data.
  168.    This method would allow multiple objects containing the same native data.
  169.    Each OBJ structure would be created on the fly when some portion of the
  170.    document was to be made into an object.  Each OBJ structure would have
  171.    only one LPOLECLIENT, which would be passed in to DocGetObject.
  172. */
  173.  
  174. typedef struct 
  175.     OLEOBJECT   oleobject;   // This must be the first field so that an 
  176.                              //   LPOLEOBJECT can be cast to a LPOBJ.
  177.     HANDLE      hObj;        // A circular handle to this structure,
  178.                              //   used to delete this structure.
  179.     LPOLECLIENT lpoleclient[clpoleclient];
  180.                              // Clients associated with the object.
  181.                              //   The array is NULL terminated.
  182.     HWND        hwnd;        // The object's own window
  183.     ATOM        aName;       // Unique identifier for each object within a doc
  184.     HPALETTE    hpal;        // Logical palette to use in drawing object
  185.     NATIVE      native;      // Object data in native format
  186. } OBJ, FAR *LPOBJ ;
  187.  
  188.  
  189.  
  190. /* Defines */
  191.  
  192. // The name of the application, used in message boxes and title bars.
  193. #define szAppName        "Server Demo"
  194.  
  195. // THe class name in the registration database.
  196. #define szClassName      "ServerDemo"
  197.  
  198. // Used to check for "-Embedding" on command line.
  199. #define szEmbeddingFlag  "Embedding" 
  200.  
  201. // Maximum length of a fully-qualified pathname.
  202. #define cchFilenameMax   256
  203.  
  204. // Maximum number of HBRUSHes.
  205. #define chbrMax          9
  206.  
  207. // Number of extra bytes in the window structure for an object
  208. #define cbWindExtra 4
  209.  
  210. // Offset (in the extra space) of the pointer to the object  
  211. #define ibLpobj          0
  212.  
  213.  
  214.  
  215. /* Global variable declarations.  (See SrvrDemo.c for descriptions.) */
  216.  
  217. extern HANDLE           hInst;
  218. extern HWND             hwndMain;
  219. extern SRVR             srvrMain;
  220. extern DOC              docMain;
  221. extern BOOL             fDocChanged;
  222. extern BOOL             fEmbedding; 
  223. extern BOOL             fRevokeSrvrOnSrvrRelease;
  224. extern BOOL             fWaitingForDocRelease;
  225. extern BOOL             fWaitingForSrvrRelease;
  226. extern BOOL             fUnblock;
  227. extern char             szClient[];
  228. extern char             szClientDoc[];
  229. extern HBRUSH           hbrColor[chbrMax];
  230. extern VERSION          version;
  231. extern OLECLIPFORMAT    cfObjectLink;
  232. extern OLECLIPFORMAT    cfOwnerLink;
  233. extern OLECLIPFORMAT    cfNative;
  234. extern OLESERVERDOCVTBL docvtbl;
  235. extern OLEOBJECTVTBL    objvtbl;
  236. extern OLESERVERVTBL    srvrvtbl;
  237.  
  238.  
  239.  
  240. /* Function Prototypes */
  241.  
  242. // Various functions
  243.  
  244. BOOL  CreateDocFromFile (LPSTR lpszDoc, LHSERVERDOC lhdoc, DOCTYPE doctype);
  245. BOOL  CreateNewDoc (LONG lhdoc, LPSTR lpszDoc, DOCTYPE doctype);
  246. LPOBJ CreateNewObj (BOOL fDoc_Changed);
  247. void  CutOrCopyObj (BOOL fOpIsCopy);
  248. void  DestroyDoc (void);
  249. void  DestroyObj (HWND hwnd);
  250. void  DeviceToHiMetric (HWND hwnd, LPPOINT lppt);
  251. void  EmbeddingModeOff (void) ;
  252. void  EmbeddingModeOn (void);
  253. void  UpdateFileMenu (int);
  254. void  ErrorBox (char *jwf);
  255. void  FreeVTbls (void);
  256. BOOL  GetFileOpenFilename (LPSTR lpszFilename);
  257. BOOL  GetFileSaveFilename (LPSTR lpszFilename);
  258. void  HiMetricToDevice (HWND hwnd, LPPOINT lppt);
  259. LPOBJ HwndToLpobj (HWND hwndObj);
  260. BOOL  InitServer (HWND hwnd, HANDLE hInst);
  261. void  InitVTbls (void);
  262. BOOL  OpenDoc (void);
  263. void  PaintObj (HWND hwnd);
  264. OLESTATUS RevokeDoc (void);
  265. void  RevokeObj (LPOBJ lpobj);
  266. int   SaveChangesOption (BOOL *pfUpdateLater);
  267. BOOL  SaveDoc (void);
  268. BOOL  SaveDocAs (void);
  269. void  SavedServerDoc (void);
  270. LPOBJ SelectedObject (void);
  271. HWND  SelectedObjectWindow (void);
  272. void  SendDocMsg (WORD wMessage );
  273. void  SendObjMsg (LPOBJ lpobj, WORD wMessage);
  274. void  SetTitle (LPSTR lpszDoc, BOOL bEmbedded);
  275. void  SetHiMetricFields (LPOBJ lpobj);
  276. void  SizeClientArea (HWND hwndMain, RECT rectReq, BOOL fFrame);
  277. void  SizeObj (HWND hwnd, RECT rect, BOOL fMove);
  278. OLESTATUS StartRevokingServer (void);
  279. void  Wait (BOOL *pf);
  280. LPSTR Abbrev (LPSTR lpsz);
  281. BOOL FAR PASCAL fnFailedUpdate (HWND, WORD, WORD, DWORD);
  282. int PASCAL WinMain 
  283.    (HANDLE  hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
  284.  
  285. // Window handlers
  286.  
  287. BOOL FAR PASCAL About       (HWND, unsigned, WORD, LONG);
  288. long FAR PASCAL MainWndProc (HWND, unsigned, WORD, LONG);
  289. long FAR PASCAL ObjWndProc  (HWND, unsigned, WORD, LONG);
  290.  
  291.                    
  292. // Server methods
  293.  
  294. OLESTATUS FAR PASCAL SrvrCreate (LPOLESERVER, LHSERVERDOC, LPSTR, LPSTR, LPOLESERVERDOC FAR *);
  295. OLESTATUS FAR PASCAL SrvrCreateFromTemplate (LPOLESERVER, LHSERVERDOC, LPSTR, LPSTR, LPSTR, LPOLESERVERDOC FAR *);
  296. OLESTATUS FAR PASCAL SrvrEdit (LPOLESERVER, LHSERVERDOC, LPSTR, LPSTR, LPOLESERVERDOC FAR * );
  297. OLESTATUS FAR PASCAL SrvrExecute (LPOLESERVER, HANDLE);
  298. OLESTATUS FAR PASCAL SrvrExit (LPOLESERVER);
  299. OLESTATUS FAR PASCAL SrvrOpen (LPOLESERVER, LHSERVERDOC, LPSTR, LPOLESERVERDOC FAR *);
  300. OLESTATUS FAR PASCAL SrvrRelease (LPOLESERVER);
  301.  
  302. // Document methods
  303.  
  304. OLESTATUS FAR PASCAL DocClose (LPOLESERVERDOC);
  305. OLESTATUS FAR PASCAL DocExecute (LPOLESERVERDOC, HANDLE);
  306. OLESTATUS FAR PASCAL DocGetObject (LPOLESERVERDOC, LPSTR, LPOLEOBJECT FAR *, LPOLECLIENT);
  307. OLESTATUS FAR PASCAL DocRelease (LPOLESERVERDOC);
  308. OLESTATUS FAR PASCAL DocSave (LPOLESERVERDOC);
  309. OLESTATUS FAR PASCAL DocSetColorScheme (LPOLESERVERDOC, LPLOGPALETTE);
  310. OLESTATUS FAR PASCAL DocSetDocDimensions (LPOLESERVERDOC, LPRECT);
  311. OLESTATUS FAR PASCAL DocSetHostNames (LPOLESERVERDOC, LPSTR, LPSTR);
  312.  
  313. // Object methods
  314.  
  315. OLESTATUS FAR PASCAL ObjDoVerb (LPOLEOBJECT, WORD, BOOL, BOOL);
  316. OLESTATUS FAR PASCAL ObjGetData (LPOLEOBJECT, OLECLIPFORMAT, LPHANDLE);
  317. LPVOID    FAR PASCAL ObjQueryProtocol (LPOLEOBJECT, LPSTR);
  318. OLESTATUS FAR PASCAL ObjRelease (LPOLEOBJECT);
  319. OLESTATUS FAR PASCAL ObjSetBounds (LPOLEOBJECT, LPRECT);
  320. OLESTATUS FAR PASCAL ObjSetColorScheme (LPOLEOBJECT, LPLOGPALETTE);
  321. OLESTATUS FAR PASCAL ObjSetData (LPOLEOBJECT, OLECLIPFORMAT, HANDLE);
  322. OLESTATUS FAR PASCAL ObjSetTargetDevice (LPOLEOBJECT, HANDLE);
  323. OLESTATUS FAR PASCAL ObjShow (LPOLEOBJECT, BOOL);
  324. OLECLIPFORMAT FAR PASCAL ObjEnumFormats (LPOLEOBJECT, OLECLIPFORMAT);
  325.  
  326.